{include 'header.tpl'}
<div class="contant">
    <div class="header">
        <div class="header_s">
            <span class="back"><a target="_blank" href="/wwwmall/add/addlist"><i class="iconfont fan">&#xe679;</i></a></span>
            <span class="title">新增收货地址</span>
            <span class="add_ads" id="baocun">保存</span>
            <div class="clear"></div>
        </div>
    </div>

    <form name="myForm"><input id="asd" type="hidden" name="myHidden" value="{$address.auto_id}"/><input id="province" type="hidden" name="province" value="{$province}"/><input id="city" type="hidden" name="city" value="{$city}"/><input id="county" type="hidden" name="county" value="{$county}"/> </form>
    <div class="adress_cont">
        <ul>

            <li class="addr_title">联系人</li>
            <li>
                <span>我的姓名</span>
                <input name="textfield" type="text" id="nickname" class="aderess_name" tabindex="1" placeholder="请输入姓名" value="{$address.contact}">
            </li>
            <li>
                <span>选择性别</span>
                <select class="adress_nas" title="1" name="sex">
                    {if $address.sex==1} <option value="1" selected="selected">男</option><option value="2">女</option>{/if}
                    {if $address.sex==2} <option value="2" selected="selected">女</option><option value="1">男</option>{/if}
                    {if $address.sex==""} <option value="1" selected="selected">男</option><option value="2">女</option>{/if}
                </select>
            </li>
            <li><span>我的手机</span>
                <input name="textfield" type="text" class="aderess_name" tabindex="1" placeholder="请输入手机号"  id="telphone" value="{$address.phone}">
            </li>

        </ul>
    </div>
    <div class="adress_cont">
        <ul>
            <li class="addr_title">收货地址</li>
            <li class="addr_shouhuo" id="county_dianji">

                <span>小区/大厦/学校:</span>
                <input type="hidden" id="address" name="field＿name" value="{$address.address}" >
                <input type="hidden" id="lat" name="lat" value="{$lat}" >
                <input type="hidden" id="lng" name="lng" value="{$lng}" >
                <input type="hidden" id="address" name="field＿name" value="{$address.address}" >
                <span class="addr_huoqu" id="address_ditu"><i class="iconfont addr_biao">&#xe650;</i>点击选择</span>
                {*<input name="textfield" type="text" class="aderess_name" tabindex="1" placeholder="请输入小区"  id="county" value="{$address.county}">*}
            </li>

            <li>
                <span>楼号-门牌号：</span>
                <input type="hidden" id="hideIpt" name="field＿name" value="{$address.auto_id}" >
                <input name="textfield" id='housemember' type="text" class="aderess_name addr_louhao" tabindex="1" placeholder="例：2号楼  1101室"
                       value="{$address.housemember}">
            </li>

        </ul>
    </div>

</div>

<script type="application/javascript" src="/mall/js/lib.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
{*<script type="application/javascript" src='http://api.map.baidu.com/api?v=2.0&ak=pRtqXqnajTytAzWDL3HOnPRK'></script>*}
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=pRtqXqnajTytAzWDL3HOnPRK"></script>
<script>

    var id = document.getElementById('asd').value;
    var location_total=$('#address').val();
//    console.log(location_total);

    if(location_total.length>0){
        $('#address_ditu').text(location_total);
        $('#address_ditu').attr('style','color:#959595');
    }

    $('#baocun').click(function (e) {

        var nick = $('#nickname').val();
        var mobile=$('#telphone').val();
        var sex = $("select[name='sex']").val();
        var province= $("#province").val();
        var city= $("#city").val();
        var county= $("#county").val();

        var housemember=$('#housemember').val();

        console.log(county);

        if(location_total.length==0){
            alert("地址不能不空");
            return false;
        }

        if(nick.length == 0  ){
            alert("称呼不能为空");
            return false;
        }


        //手机号码验证
        if(mobile.length == 0  ){
            alert("注册手机号不能为空");
            return false;
        }
        if(housemember.length == 0  ){
            alert("门牌号不能为空");
            return false;
        }

        if(mobile.length!=11)
        {
            alert('请输入有效的手机号码！');
            return false;
        }
        if(!(/^1[34578]\d\d\d\d\d\d\d\d\d$/.test(mobile))){
            alert("手机号码有误，请重填");
            return false;
        }


        $.ajax({
            url: '/add/getaddress',
            type: 'get',
            data:{
                auto_id:id,
                contact:nick,
                phone:mobile,
                address:location_total,
                sex:sex,
                province:province,
                city:city,
                county:county,
                lng:$('#lng').val(),
                lat:$('#lat').val(),
                housemember:housemember

            },
            dataType: "json",

            success:function (data) {
                if(data.status == 200){
                    {if $isback eq 1 && $id lt 1}
                        location.href="/order/submit";
                    {else}
                        location.href="/add/addlist";
                    {/if}
                }else {
                    alert(data.error);
                }

            },
            error:function (data) {
                alert('服务器异常，请稍候再试！');
            }
        })
    });


    $('#county_dianji').click(function (e) {
        var nick = $('#nickname').val();
        var mobile=$('#telphone').val();
        var sex = $("select[name='sex']").val();
        var housemember=$('#housemember').val();
         location.href='/add/Location?id='+id+'&nick='+nick+'&mobile='+mobile+'&sex='+sex+'&housemember='+housemember;
    } )


</script>
</body>
</html>
